precision mediump float;

uniform vec3 uLightPosition;

varying vec3 vPosition;
varying vec4 vColor;
varying vec3 vNormal;
   void main(){
      // Will be used for attenuation.
          float distance = length(uLightPosition - vPosition);
      	
      	// Get a lighting direction vector from the light to the vertex.
          vec3 lightVector = normalize(uLightPosition - vPosition);
      
      	// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
      	// pointing in the same direction then it will get max illumination.
      	float diffuse;
      
      	if (gl_FrontFacing) {
              diffuse = max(dot(vNormal, lightVector), 0.0);
          } else {
          	diffuse = max(dot(-vNormal, lightVector), 0.0);
          }               	  		  													  
      
      	// Add attenuation. 
          diffuse = diffuse * (1.0 / (1.0 + (0.10 * distance)));
          
          // Add ambient lighting
          diffuse = diffuse + 0.3;  
      
      	// Multiply the color by the diffuse illumination level to get final output color.
          gl_FragColor = (vColor * diffuse);
   }